package cn.hxth.cloud.provider.updater;

import cn.hxth.cloud.api.common.util.DateProvider;
import cn.hxth.cloud.api.domain.Steels;
import cn.hxth.cloud.api.mapper.SteelsMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public abstract class AbstractSteelsUpdater implements SteelsUpdater {
    private Logger logger = LoggerFactory.getLogger(AbstractSteelsUpdater.class);
    protected List<Steels> steelses;
    protected SteelsMapper SteelsMapper;
    protected DateProvider dateProvider;
    public AbstractSteelsUpdater(List<Steels> steelses, SteelsMapper steelsMapper, DateProvider dateProvider) {
        this.steelses = steelses;
        this.SteelsMapper = steelsMapper;
        this.dateProvider = dateProvider;
    }

    @Override
    public Boolean updateSteels() {
        try {
            this.updateLockedInventory();
            this.updateInventory();
             this.execute();
        } catch (Exception e) {
            logger.error("error", e);
            return false;
        }
        return true;


    }

    protected abstract void updateLockedInventory();
    protected  abstract void updateInventory() ;

    private void execute() {
        for (Steels steels : steelses) {
            this.SteelsMapper.updateByPrimaryKey(steels);
        }
    }
}
